<?php

namespace App\Http\Controllers;

use App\Models\Qnr;
use Illuminate\Http\Request;
use Illuminate\Support\Env;

class SearchQnrController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application
     */
    public function index()
    {
        return view(config('template') . '.search');
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param string $content
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application
     */
    public function show(Request $request)
    {

        $content = $request->post('content' , null);

        $result['result'] = Qnr::where('is_using' , Env::get('APP_CONTENT_STATE'))
            ->Where('content' , 'like' , '%' . $content . '%')
            ->orWhere('title' , 'like' , '%' . $content . '%')
            ->paginate(getConf('POST_VIEW_NUM'));

        return view(config('template') . '.qnr.index' , ['result' => $result]);
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request , string $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        //
    }
}
